package com.xystoy.md5api;

import lombok.extern.apachecommons.CommonsLog;
import org.rocksdb.RocksIterator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;


@Service
@CommonsLog
public class TempDataService {

    @Value("${custom.md5.cf.name}")
    private String cfName;

    public String get(String cfName, String value) throws Exception {
        return RocksTempDBUtil.get(cfName == null ? this.cfName : cfName, value);
    }

    public String get(String value) throws Exception {
        return get(this.cfName, value);
    }

    public void put(String cfName, String key, String value) throws Exception {
        RocksTempDBUtil.put(cfName == null ? this.cfName : cfName, key, value);
    }

    public void put(String key, String value) throws Exception {
        put(this.cfName, key, value);
    }

    public void delete(String cfName, String key) throws Exception {
        RocksTempDBUtil.delete(cfName == null ? this.cfName : cfName, key);
    }

    public void delete(String key) throws Exception {
        delete(this.cfName, key);
    }

    public long getCount(String cfName) throws Exception {
        return RocksTempDBUtil.getCount(cfName == null ? this.cfName : cfName);
    }

    public long getCount() throws Exception {
        return getCount(this.cfName);
    }

    public RocksIterator getNewIterator(String cfName) throws Exception {
        return RocksTempDBUtil.getNewIterator(cfName == null ? this.cfName : cfName);
    }

    public RocksIterator getNewIterator() throws Exception {
        return getNewIterator(this.cfName);
    }
}
